summaryrefslogtreecommitdiff
path: root/app/[lng]/partners/(partners)/rfq-ship/[id]/page.tsx
blob: 5b52e4a4492738cb8c4f756ca6571f6c5af2d0a9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
// app/vendor/quotations/[id]/page.tsx - 견적 응답 페이지
import { Metadata } from "next"
import { notFound } from "next/navigation"
import db from "@/db/db";
import { eq } from "drizzle-orm"
import { procurementVendorQuotations } from "@/db/schema"
import { getServerSession } from "next-auth/next"
import { authOptions } from "@/app/api/auth/[...nextauth]/route"
import VendorQuotationEditor from "@/lib/procurement-rfqs/vendor-response/quotation-editor";


interface PageProps {
  params: Promise<{
    id: string
  }>
}

export async function generateMetadata(props: PageProps): Promise<Metadata> {
  return {
    title: "견적서 응답",
    description: "RFQ에 대한 견적서 작성 및 제출",
  }
}

export default async function VendorQuotationPage(props: PageProps) {
  const params = await props.params
  const quotationId = parseInt(params.id)
  
  if (isNaN(quotationId)) {
    notFound()
  }
  
  // 인증 확인
  const session = await getServerSession(authOptions);
  
  if (!session?.user) {
    return (
      <div className="flex h-full items-center justify-center">
        <div className="text-center">
          <h2 className="text-xl font-bold">로그인이 필요합니다</h2>
          <p className="mt-2 text-muted-foreground">견적서 응답을 위해 로그인해주세요.</p>
        </div>
      </div>
    )
  }
  
  // 견적서 정보 가져오기
  const quotation = await db.query.procurementVendorQuotations.findFirst({
    where: eq(procurementVendorQuotations.id, quotationId),
    with: {
      rfq: true,      // 관계 설정 필요
      vendor: true,   // 관계 설정 필요
      items: true,    // 관계 설정 필요
    }
  })
  
  if (!quotation) {
    notFound()
  }
  
  // 벤더 권한 확인 (필요한 경우)
  const isAuthorized = session.user.domain === "partners" && 
    session.user.companyId === quotation.vendorId
  
  if (!isAuthorized) {
    return (
      <div className="flex h-full items-center justify-center">
        <div className="text-center">
          <h2 className="text-xl font-bold">접근 권한이 없습니다</h2>
          <p className="mt-2 text-muted-foreground">이 견적서에 대한 권한이 없습니다.</p>
        </div>
      </div>
    )
  }
  
  return (
    <div className="container py-8">
      <VendorQuotationEditor quotation={quotation} />
    </div>
  )
}